using UnityEngine;

namespace CinemaDirector
{
	[CutsceneItem("Tween", "ScaleFade")]
	public class GGTweenScaleFade : CinemaGlobalAction
	{
		public UIWidget widget;

		public Vector3 from;

		public Vector3 to;

		public float fromAlpha;

		public float toAlpha = 1f;

		public Interpolate.EaseType easeType;

		protected Vector3 cachedProperty;

		protected float cachedAlpha;

		public void SetProperty(Vector3 newPropertyValue, float alpha)
		{
			widget.cachedTransform.localScale = newPropertyValue;
			widget.alpha = alpha;
		}

		public virtual Vector3 GetProperty()
		{
			return widget.cachedTransform.localScale;
		}

		public virtual Vector3 GetFrom()
		{
			return from;
		}

		public virtual Vector3 GetTo()
		{
			return to;
		}

		public override void Trigger()
		{
			SetProperty(GetFrom(), fromAlpha);
		}

		public override void Initialize()
		{
			cachedProperty = GetProperty();
			cachedAlpha = widget.alpha;
		}

		public override void Stop()
		{
			if (!Application.isPlaying)
			{
				SetProperty(cachedProperty, cachedAlpha);
			}
		}

		public override void ReverseTrigger()
		{
			End();
		}

		public override void End()
		{
			SetProperty(GetTo(), toAlpha);
		}

		public override void ReverseEnd()
		{
			Trigger();
		}

		public override void UpdateTime(float time, float deltaTime)
		{
			Interpolate.Function function = Interpolate.Ease(easeType);
			Vector3 newPropertyValue = Interpolate.Ease(function, GetFrom(), GetTo() - GetFrom(), time, Mathf.Max(0.01f, base.Duration));
			float alpha = function(fromAlpha, toAlpha - fromAlpha, time, Mathf.Max(0.01f, base.Duration));
			SetProperty(newPropertyValue, alpha);
		}

		public override void SetTime(float time, float deltaTime)
		{
			if (!(time < 0f) && !(time > base.Duration))
			{
				UpdateTime(time, deltaTime);
			}
		}
	}
}
